package com.situ.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import com.situ.bean.Project;

public interface ProjectMapper {
	@Delete({ "delete from project", "where id = #{id,jdbcType=INTEGER}" })
	int deleteByPrimaryKey(Integer id);

	@Insert({ "insert into project ( name, ", "start, end, ", "bonus)", "values ( #{name,jdbcType=VARCHAR}, ",
			"#{start,jdbcType=TIMESTAMP}, #{end,jdbcType=TIMESTAMP}, ", "#{bonus,jdbcType=DECIMAL})" })
	@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
	int insert(Project record);

	@Select({ "select", "id, name, start, end, bonus", "from project", "where id = #{id,jdbcType=INTEGER}" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
			@Result(column = "start", property = "start", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "end", property = "end", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "bonus", property = "bonus", jdbcType = JdbcType.DECIMAL) })
	Project selectByPrimaryKey(Integer id);

	@Select({ "select", "id, name, start, end, bonus", "from project" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
			@Result(column = "start", property = "start", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "end", property = "end", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "bonus", property = "bonus", jdbcType = JdbcType.DECIMAL) })
	List<Project> selectAll();

	@Update({ "update project", "set name = #{name,jdbcType=VARCHAR},", "start = #{start,jdbcType=TIMESTAMP},",
			"end = #{end,jdbcType=TIMESTAMP},", "bonus = #{bonus,jdbcType=DECIMAL}",
			"where id = #{id,jdbcType=INTEGER}" })
	int updateByPrimaryKey(Project record);

	// 条件查询
	@Select({ "<script>", "select * from project ", "</script>" })
	@Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
			@Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
			@Result(column = "start", property = "start", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "end", property = "end", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "bonus", property = "bonus", jdbcType = JdbcType.DECIMAL),
			@Result(column = "id", property = "staffs", many = @Many(select = "com.situ.mapper.WorkMapper.selectByStaffProjectId")) })
	List<Project> select(Project project);
}